﻿<UserControl 
    x:Class="myManga_App.Views.HomeView_Grid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:Button="clr-namespace:myManga_App.Resources.Theme.Buttons"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:mangaObjects="clr-namespace:myMangaSiteExtension.Objects;assembly=myMangaSiteExtension"
    xmlns:Converters="clr-namespace:myManga_App.Converters"
    xmlns:CoreWPF="clr-namespace:System.Windows.Controls;assembly=Core"
    xmlns:ObjectViews="clr-namespace:myManga_App.Views.ObjectViews"
    mc:Ignorable="d" 
    d:DesignHeight="400"
    d:DesignWidth="600"
    Background="{DynamicResource window-background}" 
    Foreground="{DynamicResource window-foreground}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/myManga;component/Resources/Localization/Dictionary_en-US.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/CoreResourceDictionary.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/Button/MetroButton.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/TextBox/TextBox.xaml"/>

                <ResourceDictionary Source="/myManga;component/Themes/ListBox/ListBoxes.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/ListBox/ListBoxItems.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/ScrollBar/ScrollBar.xaml"/>

                <ResourceDictionary Source="/myManga;component/Themes/ProgressBar/Spinner.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <Converters:LoadImageFromMangaArchive x:Key="LoadImageFromMangaArchive"/>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
            <Converters:BooleanInverter x:Key="BooleanInverter"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*" MinWidth="200" MaxWidth="500"/>
            <ColumnDefinition Width="15"/>
            <ColumnDefinition Width="3*"/>
        </Grid.ColumnDefinitions>
        <ListBox
			x:Name="MangaObjectItems"
            Grid.ColumnSpan="3"
			ItemContainerStyle="{DynamicResource HomeView_Grid_MangaListBoxItem}" 
			SelectedItem="{Binding SelectedMangaArchive}"
            ItemsSource="{Binding Path=MangaArchiveCacheCollection, Mode=OneWay, Source={x:Static Application.Current}, UpdateSourceTrigger=PropertyChanged}"
            Margin="0,1,0,0"
            Padding="0,34,0,0">
            <ListBox.Template>
                <ControlTemplate TargetType="{x:Type ListBox}">
                    <ScrollViewer
                        HorizontalScrollBarVisibility="Disabled"
                        HorizontalContentAlignment="Stretch"
                        VirtualizingPanel.IsVirtualizing="True"
                        VirtualizingPanel.VirtualizationMode="Recycling">
                        <!--<Border Padding="{TemplateBinding Padding}">-->
                            <CoreWPF:BalancedWrapPanel
                                Margin="{TemplateBinding Padding}"
                                IsItemsHost="True" 
                                ItemWidth="160" 
                                ItemHeight="235"
                                HorizontalAlignment="Stretch"
                                AlignLastItems="True"/>
                        <!--</Border>-->
                    </ScrollViewer>
                </ControlTemplate>
            </ListBox.Template>
        </ListBox>
        <Grid
            Grid.ColumnSpan="3"
            Visibility="{Binding IsChecked, ElementName=MangaObjectDropdown, Converter={StaticResource BooleanToVisibilityConverter}}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="8*"/>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="8*"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>
            <Button:MetroToggleButton
                Grid.ColumnSpan="3"
                Grid.RowSpan="3"
                Background="{DynamicResource window-background}"
                PrimaryBrush="{DynamicResource window-background}"
                PrimaryDisabledBrush="{DynamicResource window-background}"
                SecondaryBrush="{DynamicResource window-background}"
                SecondaryDisabledBrush="{DynamicResource window-background}"
                Opacity="0.9"
                IsChecked="{Binding IsChecked, ElementName=MangaObjectDropdown}"/>
            <Border
                BorderBrush="{DynamicResource window-theme-primary}" 
                BorderThickness="1"
                Grid.Column="1"
                Grid.Row="1">
                <Grid>
                    <ObjectViews:MangaObjectView 
                        DataContext="{Binding SelectedItem, ElementName=MangaObjectItems}"/>
                    <Border
			            HorizontalAlignment="Left" 
			            VerticalAlignment="Top"
                        BorderBrush="{DynamicResource window-theme-primary}"
                        BorderThickness="1,1,0,1"
                        Margin="-33,-1,0,0">
                        <StackPanel 
                            Orientation="Vertical"
			                Grid.Column="2">
                            <Button:MetroButton
			                    FontFamily="{DynamicResource OpenIconic}"
			                    Content="{DynamicResource oi-reload}"
			                    Command="{Binding RefreshMangaCommand}"
			                    Height="32"
			                    Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"/>
                            <Button:MetroButton
			                    FontFamily="{DynamicResource OpenIconic}"
			                    Content="{DynamicResource oi-trash}"
			                    Command="{Binding DeleteMangaCommand}"
			                    Height="32"
			                    Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"/>
                        </StackPanel>
                    </Border>
                </Grid>
            </Border>
        </Grid>
        <Border
            Grid.ColumnSpan="2"
            Height="32"
            VerticalAlignment="Top"
            TextElement.FontSize="16"
            BorderThickness="0"
            BorderBrush="{DynamicResource window-theme-primary}" 
            Background="{DynamicResource window-background}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.InputBindings>
                    <KeyBinding Command="{Binding SearchSiteCommand}" Key="Return"/>
                    <KeyBinding Command="{Binding ClearSearchCommand}" Key="Esc"/>
                </Grid.InputBindings>
                <Button:MetroButton
					Grid.Column="0"
					FontFamily="{DynamicResource OpenIconic}"
					Content="{DynamicResource oi-magnifying-glass}"
					Command="{Binding SearchSiteCommand}"
					ToolTip="Search Sites"
					Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"/>
                <TextBox
					x:Name="SearchBox"
					Grid.Column="1" 
					BorderBrush="{x:Null}" 
					BorderThickness="0" 
					Background="{x:Null}"
					VerticalContentAlignment="Center"
					Text="{Binding SearchFilter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <Button:MetroToggleButton 
					x:Name="AdvSrchBtn"
					Grid.Column="2"
					Content="{DynamicResource fa-sort-down}"
					FontFamily="{DynamicResource FontAwesome}"
					ToolTip="Advanced Search" Visibility="Collapsed"/>
                <Popup 
					PopupAnimation="Slide" 
					PlacementTarget="{Binding ElementName=AdvSrchBtn}"
					IsOpen="{Binding IsChecked, ElementName=AdvSrchBtn}"
					StaysOpen="False">
                    <Border
						BorderThickness="1" 
						BorderBrush="{DynamicResource window-theme-primary}" 
						Background="{DynamicResource window-background}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Button:MetroToggleButton Content="Action" Grid.Column="0" Grid.Row="0"/>
                            <Button:MetroToggleButton Content="Adventure" Grid.Column="1" Grid.Row="0"/>
                            <Button:MetroToggleButton Content="Comedy" Grid.Column="2" Grid.Row="0"/>
                            <Button:MetroToggleButton Content="Demons" Grid.Column="3" Grid.Row="0"/>
                            <Button:MetroToggleButton Content="Drama" Grid.Column="4" Grid.Row="0"/>

                            <Button:MetroToggleButton Content="Ecchi" Grid.Column="0" Grid.Row="1"/>
                            <Button:MetroToggleButton Content="Fantasy" Grid.Column="1" Grid.Row="1"/>
                            <Button:MetroToggleButton Content="Gender Bender" Grid.Column="2" Grid.Row="1"/>
                            <Button:MetroToggleButton Content="Harem" Grid.Column="3" Grid.Row="1"/>
                            <Button:MetroToggleButton Content="Historical" Grid.Column="4" Grid.Row="1"/>

                            <Button:MetroToggleButton Content="Horror" Grid.Column="0" Grid.Row="2"/>
                            <Button:MetroToggleButton Content="Josei" Grid.Column="1" Grid.Row="2"/>
                            <Button:MetroToggleButton Content="Magic" Grid.Column="2" Grid.Row="2"/>
                            <Button:MetroToggleButton Content="Martial Arts" Grid.Column="3" Grid.Row="2"/>
                            <Button:MetroToggleButton Content="Mature" Grid.Column="4" Grid.Row="2"/>

                            <Button:MetroToggleButton Content="Mecha" Grid.Column="0" Grid.Row="3"/>
                            <Button:MetroToggleButton Content="Military" Grid.Column="1" Grid.Row="3"/>
                            <Button:MetroToggleButton Content="Mystery" Grid.Column="2" Grid.Row="3"/>
                            <Button:MetroToggleButton Content="One Shot" Grid.Column="3" Grid.Row="3"/>
                            <Button:MetroToggleButton Content="Psychological" Grid.Column="4" Grid.Row="3"/>

                            <Button:MetroToggleButton Content="Romance" Grid.Column="0" Grid.Row="4"/>
                            <Button:MetroToggleButton Content="School Life" Grid.Column="1" Grid.Row="4"/>
                            <Button:MetroToggleButton Content="Sci-Fi" Grid.Column="2" Grid.Row="4"/>
                            <Button:MetroToggleButton Content="Seinen" Grid.Column="3" Grid.Row="4"/>
                            <Button:MetroToggleButton Content="Shoujo" Grid.Column="4" Grid.Row="4"/>

                            <Button:MetroToggleButton Content="Shoujoai" Grid.Column="0" Grid.Row="5"/>
                            <Button:MetroToggleButton Content="Shounen" Grid.Column="1" Grid.Row="5"/>
                            <Button:MetroToggleButton Content="Shounenai" Grid.Column="2" Grid.Row="5"/>
                            <Button:MetroToggleButton Content="Slice of Life" Grid.Column="3" Grid.Row="5"/>
                            <Button:MetroToggleButton Content="Smut" Grid.Column="4" Grid.Row="5"/>

                            <Button:MetroToggleButton Content="Sports" Grid.Column="0" Grid.Row="6"/>
                            <Button:MetroToggleButton Content="Super Power" Grid.Column="1" Grid.Row="6"/>
                            <Button:MetroToggleButton Content="Supernatural" Grid.Column="2" Grid.Row="6"/>
                            <Button:MetroToggleButton Content="Tragedy" Grid.Column="3" Grid.Row="6"/>
                            <Button:MetroToggleButton Content="Vampire" Grid.Column="4" Grid.Row="6"/>

                            <Button:MetroToggleButton Content="Yaoi" Grid.Column="0" Grid.Row="7"/>
                            <Button:MetroToggleButton Content="Yuri" Grid.Column="1" Grid.Row="7"/>
                            <Button:MetroButton Content="Clear" Grid.Column="4" Grid.Row="7"/>
                        </Grid>
                    </Border>
                </Popup>
                <Button:MetroButton
					Grid.Column="3"
					FontFamily="{DynamicResource OpenIconic}"
					Content="{DynamicResource oi-delete}"
					Command="{Binding ClearSearchCommand}"
					ToolTip="Clear Search"
					Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"/>
                <Button:MetroButton
					Grid.Column="4"
			        FontFamily="{DynamicResource OpenIconic}"
			        Content="{DynamicResource oi-reload}"
				    ContentStringFormat="{}Refresh {0}"
                    VerticalContentAlignment="Center"
			        Command="{Binding RefreshMangaListCommand}"/>
            </Grid>
        </Border>
        <Button:MetroToggleButton 
            x:Name="MangaObjectDropdown"
            Grid.ColumnSpan="1"
            Grid.Column="2"
            VerticalAlignment="Top"
            HorizontalAlignment="Right"
            Width="200"
            Height="32"
            Margin="0,0,16,0"
            IsHitTestVisible="{Binding IsOpen, Converter={StaticResource BooleanInverter}, ElementName=MangaObjectPopup, Mode=OneWay}">
            <Button:MetroToggleButton.Content>
                <TextBlock Text="More Information" FontSize="18"/>
            </Button:MetroToggleButton.Content>
        </Button:MetroToggleButton>
    </Grid>
</UserControl>
